package com.hanthink.web.controller.pc;

import java.util.List;

import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.pc.EmJobItem;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.manhour.MachineTheoryWorkers;
import com.hanthink.system.service.manhour.IMachineTheoryWorkersService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 设备物料理论用工数Controller
 * 
 * @author hanthink
 * @date 2021-11-22
 */
@RestController
@RequestMapping("/system/MachineTheoryWorkers")
public class MachineTheoryWorkersController extends BaseController
{
    @Autowired
    private IMachineTheoryWorkersService machineTheoryWorkersService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询设备物料理论用工数列表
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:list')")
    @GetMapping("/list")
    public TableDataInfo list(MachineTheoryWorkers machineTheoryWorkers)
    {
        startPage();
        List<MachineTheoryWorkers> list = machineTheoryWorkersService.selectMachineTheoryWorkersList(machineTheoryWorkers);
        return getDataTable(list);
    }

    /**
     * 导出设备物料理论用工数列表
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:export')")
    @Log(title = "设备物料理论用工数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MachineTheoryWorkers machineTheoryWorkers)
    {
        List<MachineTheoryWorkers> list = machineTheoryWorkersService.selectMachineTheoryWorkersList(machineTheoryWorkers);
        ExcelUtil<MachineTheoryWorkers> util = new ExcelUtil<MachineTheoryWorkers>(MachineTheoryWorkers.class);
        return util.exportExcel(list, "MachineTheoryWorkers");
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate() {
        //EmJobItem
        ExcelUtil<MachineTheoryWorkers> util = new ExcelUtil<MachineTheoryWorkers>(MachineTheoryWorkers.class);
        return util.importTemplateExcel("设备物料理论用工");
    }

    @Log(title = "设备物料理论用工数", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<MachineTheoryWorkers> util = new ExcelUtil<MachineTheoryWorkers>(MachineTheoryWorkers.class);
        List<MachineTheoryWorkers> itemList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = machineTheoryWorkersService.importMachineTheoryWorkersitem(itemList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    /**
     * 获取设备物料理论用工数详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(machineTheoryWorkersService.selectMachineTheoryWorkersById(id));
    }

    /**
     * 新增设备物料理论用工数
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:add')")
    @Log(title = "设备物料理论用工数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MachineTheoryWorkers machineTheoryWorkers)
    {
        return toAjax(machineTheoryWorkersService.insertMachineTheoryWorkers(machineTheoryWorkers));
    }

    /**
     * 修改设备物料理论用工数
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:edit')")
    @Log(title = "设备物料理论用工数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MachineTheoryWorkers machineTheoryWorkers)
    {
        return toAjax(machineTheoryWorkersService.updateMachineTheoryWorkers(machineTheoryWorkers));
    }

    /**
     * 删除设备物料理论用工数
     */
    @PreAuthorize("@ss.hasPermi('system:MachineTheoryWorkers:remove')")
    @Log(title = "设备物料理论用工数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(machineTheoryWorkersService.deleteMachineTheoryWorkersByIds(ids));
    }
}
